/**
 * 
 */
package com.alphasystem.commerce.common.annotation.apt;

import java.io.File;
import java.util.Map;
import java.util.Map.Entry;

import com.alphasystem.commerce.common.util.JAXBUtil;
import com.alphasystem.commerce.ui.cmc.ComponentType;
import com.alphasystem.commerce.ui.cmc.ComponentsType;
import com.alphasystem.commerce.ui.cmc.ObjectFactory;

/**
 * @author sali
 * 
 */
public class JaxbPersistenceHelperImpl implements PersistenceHelper {

	public void saveAsXml(File outFile, Map<String, ComponentType> components) {
		ObjectFactory objectFactory = new ObjectFactory();
		ComponentsType root = objectFactory.createComponentsType();

		for (Entry<String, ComponentType> entry : components.entrySet()) {
			root.getComponent().add(entry.getValue());
		}
		JAXBUtil.marshall(outFile, root.getClass().getPackage().getName(),
				objectFactory.createComponents(root), "ui.xsd");
	}

}
